package com.bawei.lizhiyu1228.ui.act;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import android.content.Intent;
import android.view.View;
import android.widget.TableLayout;

import com.bawei.lizhiyu1228.R;
import com.bawei.lizhiyu1228.foot.Foot;
import com.bawei.lizhiyu1228.foot.FootModel;
import com.bawei.lizhiyu1228.foot.FootPresenter;
import com.bawei.lizhiyu1228.foot.MyContract;
import com.bawei.lizhiyu1228.mvp.v.BaseActivity;
import com.bawei.lizhiyu1228.ui.act.FootActivity;
import com.bawei.lizhiyu1228.ui.adapter.FootAdapter;
import com.blankj.utilcode.util.BarUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class MainActivity extends BaseActivity<FootPresenter> implements MyContract.FoodView{



    private TableLayout actTab;
    private RecyclerView actRv;

    @Override
    public int beanLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {


        actTab = (TableLayout) findViewById(R.id.act_tab);
        actRv = (RecyclerView) findViewById(R.id.act_rv);

        actRv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
    }

    @Override
    public void initData() {

        BarUtils.transparentStatusBar(this);
        BarUtils.transparentStatusBar(getWindow());

        FootPresenter footPresenter = new FootPresenter(this, new FootModel());
        footPresenter.getFood();
    }

    @Override
    public void foodView(List<Foot.DataBean> dataBeans) {

        FootAdapter footAdapter = new FootAdapter(dataBeans);

        actRv.setAdapter(footAdapter);
        footAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
                Intent intent = new Intent(getApplicationContext(), FootActivity.class);
                intent.putExtra("pic",dataBeans.get(position).getPic());
                intent.putExtra("tv",dataBeans.get(position).getTitle());
                startActivity(intent);
            }
        });
    }
}